package com.todomvc.fw;

public class Todo {
	private boolean isCompleted;
	private String text;

	public Todo () {
		this.isCompleted = false;
		this.text = "";
	}
	

	public Todo (String text) {
		this.isCompleted = false;
		this.text = text;
	}


	public Todo (boolean isCompleted, String text) {
		this.isCompleted = isCompleted;
		this.text = text;
	}


	public boolean isCompleted() {
		return isCompleted;
	}


	public Todo setCompleted(boolean isCompleted) {
		this.isCompleted = isCompleted;
		return this;
	}

	
	public Todo toggleCompleted() {
		this.isCompleted = !this.isCompleted;
		return this;
	}
	

	public String getText() {
		return text;
	}


	public Todo setText(String text) {
		this.text = text;
		return this;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (isCompleted ? 1231 : 1237);
		result = prime * result + ((text == null) ? 0 : text.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Todo other = (Todo) obj;
		if (isCompleted != other.isCompleted)
			return false;
		if (text == null) {
			if (other.text != null)
				return false;
		} else if (!text.equals(other.text))
			return false;
		return true;
	}


	@Override
	public String toString() {
		return "Todo [isCompleted=" + isCompleted + ", text=" + text + "]";
	}
}
